var ChartTypes = function()
{
	this.xlArea = 1;
	this.xlLine = 4;
	this.xlPie = 5;
	this.xlBubble = 15;
	this.xlColumnClustered = 51;
	this.xlColumnStacked = 52;
	this.xlColumnStacked100 = 53;
	this.xl3DColumnClustered = 54;
	this.xl3DColumnStacked = 55;
	this.xl3DColumnStacked100 = 56;
	this.xlBarClustered = 57;
	this.xlBarStacked = 58;
	this.xlBarStacked100 = 59;
	this.xl3DBarClustered = 60;
	this.xl3DBarStacked = 61;
	this.xl3DBarStacked100 = 62;
	this.xlLineStacked = 63;
	this.xlLineStacked100 = 64;
	this.xlLineMarkers = 65;
	this.xlLineMarkersStacked = 66;
	this.xlLineMarkersStacked100 = 67;
	this.xlPieOfPie = 68;
	this.xlPieExploded = 69;
	this.xl3DPieExploded = 70;
	this.xlBarOfPie = 71;
	this.xlXYScatterSmooth = 72;
	this.xlXYScatterSmoothNoMarkers = 73;
	this.xlXYScatterLines = 74;
	this.xlXYScatterLinesNoMarkers = 75;
	this.xlAreaStacked = 76;
	this.xlAreaStacked100 = 77;
	this.xl3DAreaStacked = 78;
	this.xl3DAreaStacked100 = 79;
	this.xlDoughnutExploded = 80;
	this.xlRadarMarkers = 81;
	this.xlRadarFilled = 82;
	this.xlSurface = 83;
	this.xlSurfaceWireframe = 84;
	this.xlSurfaceTopView = 85;
	this.xlSurfaceTopViewWireframe = 86;
	this.xlBubble3DEffect = 87;
	this.xlStockHLC = 88;
	this.xlStockOHLC = 89;
	this.xlStockVHLC = 90;
	this.xlStockVOHLC = 91;
	this.xlCylinderColClustered = 92;
	this.xlCylinderColStacked = 93;
	this.xlCylinderColStacked100 = 94;
	this.xlCylinderBarClustered = 95;
	this.xlCylinderBarStacked = 96;
	this.xlCylinderBarStacked100 = 97;
	this.xlCylinderCol = 98;
	this.xlConeColClustered = 99;
	this.xlConeColStacked = 100;
	this.xlConeColStacked100 = 101;
	this.xlConeBarClustered = 102;
	this.xlConeBarStacked = 103;
	this.xlConeBarStacked100 = 104;
	this.xlConeCol = 105;
	this.xlPyramidColClustered = 106;
	this.xlPyramidColStacked = 107;
	this.xlPyramidColStacked100 = 108;
	this.xlPyramidBarClustered = 109;
	this.xlPyramidBarStacked = 110;
	this.xlPyramidBarStacked100 = 111;
	this.xlPyramidCol = 112;
	this.xlXYScatter = -4169;
	this.xlRadar = -4151;
	this.xlDoughnut = -4120;
	this.xl3DPie = -4102;
	this.xl3DLine = -4101;
	this.xl3DColumn = -4100;
	this.xl3DArea = -4098;
}
var ChartGenerator = function()
{
	this.chartypes = new ChartTypes();
	this.createchart = function(ptitle, ptype, prl, paxisname, pfn)
	{
		var ret = pfn;
		if(!ret)
		{
			ret = (new FileUtil()).gettempfilename(".gif");
		}
		var app = new ActiveXObject("Excel.Application");
		app.DisplayAlerts = false;
		var book = app.Workbooks.Add();
		var maxsheetcount = book.Worksheets.Count;
		for(var scnt = 0; scnt < maxsheetcount - 1; scnt++)
		{
			book.Worksheets.Item(maxsheetcount - scnt).Delete();
		}

		var sheet = book.Worksheets.Item(1);
		var ir = sheet.Range("A1");
		var cols = new Array();
		cols.length = 0;
		for(var rcnt = 0; rcnt < prl.length; rcnt++)
		{
			var re = prl[rcnt];
			if(rcnt == 0)
			{
				cols[cols.length] = paxisname;
				for(var pn in re)
				{
					if(pn != paxisname)
					{
						cols[cols.length] = pn;
					}
				}
				for(var ccnt = 0; ccnt < cols.length; ccnt++)
				{
					ir.Offset(rcnt, ccnt).Value2 = cols[ccnt];
				}
			}
			for(var ccnt = 0; ccnt < cols.length; ccnt++)
			{
				ir.Offset(rcnt + 1, ccnt).Value2 = re[cols[ccnt]];
			}
		}
		var chart = book.Charts.Add();
		chart.HasTitle = true;
		chart.ChartTitle.Text = ptitle;
		chart.ChartType = this.chartypes[ptype];
		chart.Export(ret);
		book.Close();
		app.Quit();
		return ret;
	}
}

